$(function(){

  // 获取ulr参数
  var paramId = GetRequest().id
  var param = 100 + Number(GetRequest().id)
  

 //  副标题
 var subtitle
 if(param == 1) {
  subtitle = '海南话4级考试'
 }

//  随机链接软文
 var randomArr = ['https://mp.weixin.qq.com/s/K0jdWidQq1vUFdeiIl9zyQ',
                  'https://mp.weixin.qq.com/s/JDppXK2LZ64nDJ-Rxu5KXw',
                  'https://mp.weixin.qq.com/s/tJq6zNpLk6Cwau5Zt4o2yQ'
                 ]
 var randNum = Math.round(Math.random() * (randomArr.length - 1));
 var _link = $('#link')
 console.log(randNum, 'nnnnnnnnnn')
 _link.find('a').attr('href', randomArr[randNum])
 _link.click(function() {
  visitNum(param, 3)
 })
 
  var testData = [
    {
      "test": [
        {
          "title": '1、半鸡固是什么意思？ ',
          "option": [
            {id: 1, score: '0', name: 'A、很聪明'},{id: 1, score: '0', name: 'B、很厉害'},{id: 1, score: '5', name: 'C、很死板'},{id: 1, score: '0', name: 'D、很漂亮 '}
          ]
        },
        {
          "title": '2、落鼓是什么东西？ ',
          "option": [
            {id: 2, score: '0', name: 'A、打击乐器'},{id: 2, score: '0', name: 'B、高雅艺术'},{id: 2, score: '0', name: 'C、民间传说'},{id: 2, score: '5', name: 'D、脑有问题 '}
          ]
        },
        {
          "title": '3、九酸看见一个九酸，讲：“咿呀，鲁比我养九酸！”请问九酸为何物？ ',
          "option": [
            {id: 3, score: '0', name: 'A、傻子'},{id: 3, score: '0', name: 'B、文盲'},{id: 3, score: '0', name: 'C、小人'},{id: 3, score: '5', name: 'D、猴子 '}
          ]
        },
        {
          "title": '4、公期”是海南人喜欢过的一个节日，这个节相当于普通话里的?  ',
          "option": [
            {id: 4, score: '0', name: 'A、端午节'},{id: 4, score: '0', name: 'B、宵节'},{id: 4, score: '0', name: 'C、春节'},{id: 4, score: '5', name: 'D、军坡节 '}
          ]
        },
        {
          "title": '5、单阿系是哪里？ ',
          "option": [
            {id: 5, score: '0', name: 'A、海口市'},{id: 5, score: '5', name: 'B、三亚市 '},{id: 5, score: '0', name: 'C、五指山'},{id: 5, score: '0', name: 'D、万宁'}
          ]
        },
        {
          "title": '6、海南话“凹日”是指 ？ ',
          "option": [
            {id: 6, score: '0', name: 'A、今天'},{id: 6, score: '0', name: 'B、明天'},{id: 6, score: '5', name: 'C、后天'},{id: 6, score: '0', name: 'D、前天 '}
          ]
        },
        {
          "title": '7、“麦仔”相当于普通话的？ ',
          "option": [
            {id: 7, score: '0', name: 'A、麦子'},{id: 7, score: '0', name: 'B、稻谷'},{id: 7, score: '0', name: 'C、麦克风'},{id: 7, score: '5', name: 'D、妹子 '}
          ]
        },
        {
          "title": '8、普通话“你好”，海南话怎么说？  ',
          "option": [
            {id: 8, score: '0', name: 'A、嗲嗲'},{id: 8, score: '0', name: 'B、嘿吼'},{id: 8, score: '5', name: 'C、鲁哦'},{id: 8, score: '0', name: 'D、鲁呼底 '}
          ]
        },
        {
          "title": '9、印迪”是什么意思？  ',
          "option": [
            {id: 9, score: '0', name: 'A、现实'},{id: 9, score: '0', name: 'B、丑陋 '},{id: 9, score: '0', name: 'C、印花'},{id: 9, score: '5', name: 'D、风流 '}
          ]
        },
        {
          "title": '10、“番豆糖方”是什么意思？ ',
          "option": [
            {id: 10, score: '0', name: 'A、豆子好香'},{id: 10, score: '5', name: 'B、花生好香'},{id: 10, score: '0', name: 'C、爆米花好香'},{id: 10, score: '0', name: 'D、四季豆香'}
          ]
        },
        {
          "title": '11、公婆鲁就萨GI哆,是指什么？ ',
          "option": [
            {id: 11, score: '0', name: 'A、给爷爷奶奶做饭'},{id: 11, score: '5', name: 'B、当好家长'},{id: 11, score: '0', name: 'C、自己一个人拜祖先'},{id: 11, score: '0', name: 'D、叫爷爷奶奶吃饭'}
          ]
        },
        {
          "title": '12、“勾母”普通话正确的翻译是？ ',
          "option": [
            {id: 12, score: '0', name: 'A、勾引母猪'},{id: 12, score: '0', name: 'B、母亲的妹妹'},{id: 12, score: '0', name: 'C、母鸡上勾'},{id: 12, score: '5', name: 'D、父亲的妹妹'}
          ]
        },
        {
          "title": '13、“咿呀，你么小仔屎也来绍娘，我六打鲁么剪吹笔哥！”剪吹为何意?  ',
          "option": [
            {id: 13, score: '0', name: 'A、理发'},{id: 13, score: '0', name: 'B、吹牛'},{id: 13, score: '0', name: 'C、吃饭'},{id: 13, score: '5', name: 'D、屁股'}
          ]
        },
        {
          "title": '14、啊狗么牛爹室婆个新部外家么姑强个滚审个圆强子对岁。文章里出现了几个人？ ',
          "option": [
            {id: 14, score: '0', name: 'A、4个'},{id: 14, score: '0', name: 'B、5个'},{id: 14, score: '0', name: 'C、6个'},{id: 14, score: '5', name: 'D、7个'}
          ]
        },
        {
          "title": '15、“嘟V”是什么意思？ ',
          "option": [
            {id: 15, score: '0', name: 'A、V的手势'},{id: 15, score: '0', name: 'B、没味道'},{id: 15, score: '5', name: 'C、有意思'},{id: 15, score: '0', name: 'D、没意思'}
          ]
        },
        {
          "title": '16、“嘎德拉”相当于普通话的？ ',
          "option": [
            {id: 16, score: '0', name: 'A、麦子'},{id: 16, score: '0', name: 'B、稻谷'},{id: 16, score: '0', name: 'C、麦克风'},{id: 16, score: '5', name: 'D、捣乱'}
          ]
        },
        {
          "title": '17、“瓜底啦”是什么意思？',
          "option": [
            {id: 17, score: '0', name: 'A、好凉快'},{id: 17, score: '0', name: 'B、好热啊'},{id: 17, score: '5', name: 'C、冷死了'},{id: 17, score: '0', name: 'D、好难受'}
          ]
        },
        {
          "title": '18、“噢耐”是什么意思？  ',
          "option": [
            {id: 18, score: '5', name: 'A、难受'},{id: 18, score: '0', name: 'B、开心'},{id: 18, score: '0', name: 'C、哭泣'},{id: 18, score: '0', name: 'D、说话'}
          ]
        },
        {
          "title": '19、“计咋”是什么意思？  ',
          "option": [
            {id: 19, score: '0', name: 'A、现实'},{id: 19, score: '5', name: 'B、臭美'},{id: 19, score: '0', name: 'C、计算'},{id: 19, score: '0', name: 'D、算计'}
          ]
        },
        {
          "title": '20、啵几啵意是什么意思？ ',
          "option": [
            {id: 10, "last": true, score: '0', name: 'A、不情不愿'},{id: 10, "last": true, score: '0', name: 'B、薄情薄意  '},{id: 10, "last": true, score: '5', name: 'C、没钱没铁'},{id: 10, "last": true, score: '0', name: 'D、碎碎念'}
          ]
        }
      ]
    }
  ]

  $.each(testData,function(i,item){
    var index = i+1;
    if(index == paramId) {
      $("#tpl").tmpl(item).appendTo('#div_demo');
     }
  });

  var lists=$('.group');
  lists.hide();
  lists.first().show();

  var sumScore = 0
  var lastScore = 0
  var allScore = 0
  var sub = 1
  var _modal = $('.modal')
  var _btn = $('.answer-btn-box')
  var _options = $('.options-item')
  var _result = $('.answer-result')
  _options.click(function(){
    var _this = $(this);
    paramId = _this.attr('data-index')
    index = _this.attr('data-index')
    _this.addClass('active').siblings().removeClass('active');
    lists.eq(sub).show().siblings().hide();
    sub++
    if(_this.attr('data-last') == 'true') {
      _btn.show()
      lastScore = Number(_this.attr('data-score'))
    } else {
      sumScore += Number(_this.attr('data-score'))
    }
    allScore = sumScore + lastScore
    console.log(allScore, 'sumScoresumScoresumScore')
  })

  

  _btn.click(function(){
    lists.hide();
    _btn.hide();
    _result.show();
    _modal.hide();
    $("#scroe").append(allScore);
  })
  _modal.click(function(){
    $(this).hide();
  })

   // 分享功能
   initData()
   var timestamp,nonceStr,signature,appId;
   function initData() {
     var url0 = location.href.split('#').toString();//url不能写死
     $.ajax({
       type:'get',
       url: "https://iwan8.club/wx/jssdk/getConfig", 
       data: { url: url0, oid: '0',attr: '1' },
       success: function(res){
         var data = JSON.parse(res).result
           timestamp = data.timestamp
           nonceStr = data.nonceStr
           signature = data.signature
           appId = data.appid
           wx.config({
             debug: false, // 是否开启调试模式
             appId: appId, //appid
             timestamp: timestamp, // 时间戳
             nonceStr: nonceStr, // 随机字符串
             signature: signature, // 签名
             jsApiList: [
               'onMenuShareTimeline',
               'onMenuShareAppMessage',
             ] // 需要使用的JS接口列表
           })
           wx.ready(function() {
             // 分享朋友圈
             wx.onMenuShareTimeline({
               title: subtitle, // 分享标题
               desc: '你也来测测', // 分享描述
               imgUrl: 'https://iwan8.club/wechatRes/res/img/wx/tree.png', // 分享图标
               link: 'https://iwan8.club/wx/3.html?id='+paramId, // 分享链接
               success: function () {
                 lists.hide();
                 _btn.hide();
                 _result.show();
                 _modal.hide();
                 $("#scroe").append(allScore);
                 console.log(param, '成功后的回调')
                //  成功回调访问统计
                visitNum(param, 2)
               },
               cancel: function () {
                   // 用户取消分享后执行的回调函数
               }
             });
             // 分享给好友
             wx.onMenuShareAppMessage({
             title: subtitle, // 分享标题
             desc: '你也来测测', // 分享描述
             link: 'link', // 分享链接
             imgUrl: 'https://iwan8.club/wechatRes/res/img/wx/tree.png', // 分享图标
             link: 'https://iwan8.club/wx/3.html?id='+paramId, // 分享链接
             success: function () {
               lists.hide();
               _btn.hide();
               _result.show();
               _modal.hide();
               $("#scroe").append(allScore);
              //  成功回调访问统计
              visitNum(param, 2)
             },
             error: function() {
               alert("失败");
             },
             cancel: function () {
               alert('取消分享')
             }
             })
           })
       },
       error: function() {
       },
     });
   }
   // 访问统计
   visitNum(param, 1)
})